<?php

namespace App\Admin\Controllers;

use App\Models\Journal;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class JournalController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Journal::class, function (Grid $grid) {

            $grid->id('ID')->sortable();
            $grid->name_short('期刊分类');
            $grid->name_full('期刊名称');
            $grid->name_short('期刊简称');
            $grid->journal_url('期刊网址');
            $grid->volume('ISSN号');
            $grid->cn('CN号');
            $grid->created_at();
            $grid->updated_at();
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableView();
            });

        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Journal::class, function (Form $form) {

            $form->display('id', 'ID');

            $form->text('name_full', '期刊名称')->rules('required');
            $form->text('name_full_en', '期刊名称(英文)')->rules('required');
            $form->text('name_short', '期刊简称')->rules('required')    ;
            $form->text('name_short_en', '期刊简称(英文)')->rules('required|regex:/\w/',['regex'=>'请使用数字字母']);
            $form->url('journal_url', '期刊网址');
            $form->text('issn', 'ISSN号')->rules('required');
            $form->text('eissn', 'EISSN号');
            $form->text('cn', 'CN号')->rules('required');
            // $form->text('journal_league_url ', '期刊联盟地址')->rules('nullable|url');
            // $form->text('weibo_url', '期刊联盟地址')->rules('nullable|url');

            // $attr = [
            //     0 => '期刊分类',
            //     1 => '期刊群',
            // ];
            // $form->select('order', '期刊属性')->options($attr)->default(0);

            // $language = [
            //     0 => '中文',
            //     1 => '英文',
            // ];
            // $form->select('language', '期刊语言')->options($language)->default(0);

           //  $oa = [
           //      0 => '是',
           //      1 => '否',
           //  ];
           // $form->select('is_oa', '是否OA')->options($oa)->default(0);

            // $database   = [
            //     0 => '请选择',
            //     1 => 'SpringerLink',
            //     2 => 'Crossref',
            // ];
            // $form->select('database', '获取被引次数的数据库')->options($database)->default(0);
            // $form->text('font_color', '高亮字体颜色');
            $form->text('email', '服务器地址')->rules('required');

            $form->select('smtp', '加密方式')->options(array(
                'tls' => 'tls',
                'ssl' => 'ssl',
            ))->default('ssl');
            $form->text('port', '发送端口号')->rules('required');
            $form->email('email_name', '邮件地址')->rules('required');
            $form->password('email_password', '邮件密码')->rules('required');

            // $encode = [
            //     0 => 'GB2312',
            //     1 => 'UTF-8',
            // ];
            // $form->select('encode', '获取被引次数的数据库')->options($encode)->default(0)->rules('required');


            // $ssl   = [
            //     0 => '是',
            //     1 => '否',
            // ];
            // $form->select('is_ssl', '文章排序类型')->options($ssl)->default(0)->rules('required');
            // $form->text('ssl_port', 'SSL端口号')->rules('required');
            // $validate = [
            //     0 => '是',
            //     1 => '否',
            // ];
            // $form->select('is_validate', '是否需要身份验证')->options($validate)->default(0)->rules('required');

            // $free = [
            //     0 => '是',
            //     1 => '否',
            // ];
            // $form->select('is_free', '是否全部免费开放全文')->options($free)->default(0);

            // $split  = [
            //     0 => '是',
            //     1 => '否',
            // ];
            // $form->select('is_split', '参考文献是否拆分')->options($split)->default(0);

            // $crossref  = [
            //     0 => '是',
            //     1 => '否',
            // ];
            // $form->select('is_crossref', '参考文献是否从Crossref中查找DOI')->options($split)->default(0);

            // $toc  = [
            //     0 => '中文',
            //     1 => '英文',
            //     2 => '全部',
            // ];
            // $form->select('toc', '将Email写入Toc中的【中英文】选项')->options($toc)->default(0);
            $form->image('cover', '封面默认图片')->uniqueName();
            $form->multipleImage('qr_code', '首页二维码')->removable();
            // $form->image('cover_en', ' 封面默认图片（英文）')->uniqueName();
            // $type  = [
            //     0 => 'PACS',
            // ];
            // $form->select('type', '分类号类别')->options($type)->default(0);
            // $is_editor   = [
            //     0 => '是',
            //     1 => '否',
            // ];
            // $form->select('is_editor ', '录入文章界面是否调用编辑器')->options($is_editor )->default(0);
            // $form->text('cdkey', '序列号');
            // $form->text('copy_right', '版权所有');
            // $form->text('address', '地址');
            // $form->text('post_code ', '邮编');
            // $form->text('telephone', '电话');
            // $form->text('fax', '传真');
            // $form->text('email_web ', 'Email');
            // $form->text('icp', '备案号');

            $form->display('created_at', 'Created At');
            $form->display('updated_at', 'Updated At');
            $form->disableViewCheck();
            $form->disableEditingCheck();
            $form->tools(function(\Encore\Admin\Form\Tools $tools) {
                $tools->disableView();
            });
        });
    }
}
